﻿using SqlSugar;
using System.Reflection;

namespace ProductManagement.Infrstructre
{
    public class ProductsDbcontext
    {
        protected readonly ISqlSugarClient db;

        public ProductsDbcontext(ISqlSugarClient db)
        {
            this.db = db;
        }

        public void CreateDatabase()
        {
            db.DbMaintenance.CreateDatabase();
            var rootBath = AppDomain.CurrentDomain.BaseDirectory;
            Type[] types = Assembly
                .LoadFrom(rootBath + "ProductManagement.Domain.dll")
                .GetTypes().Where(it => it.FullName.Contains("ProductManagement.Domain.ProductsDomain"))
                .ToArray();

            db.CodeFirst.SetStringDefaultLength(200).InitTables(types);
        }
    }
}
